﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Web.Mvc;
using CommandLib;

namespace Services.Controllers
{
    public class ImagesController : Controller
    {
        //
        // GET: /Images/

        public ActionResult Index(string images, string typeImages, int year, int month, string name)
        {
            string urlImage = string.Format("{0}/{1}/{2}/{3}/{4}/{5}", Config.FolderImage, images, typeImages, year, month, name);
            if (!System.IO.File.Exists(urlImage))
            {
                urlImage = Config.FolderImage + "default.png";
            }
            var imgResponse = Image.FromFile(urlImage);

            var temp = new MemoryStream();
            imgResponse.Save(temp, System.Drawing.Imaging.ImageFormat.Jpeg);
            return File(temp.ToArray(), Utils.GetMimeType(urlImage));           
        }

    }
}
